package com.example.springboot_zc.controller;

import com.example.springboot_zc.pojo.User;
import com.example.springboot_zc.service.classService;
import com.example.springboot_zc.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.springboot_zc.pojo.Class;

import java.util.List;

@RestController
@RequestMapping("/class")
public class classController {

    @Autowired
    private classService classService;

    @Autowired
    private userService userService;

  /*  @GetMapping("/getAll")
    public List<Class> getAll(){
        return classService.getAllClass();
}*/
    @GetMapping("/zhong")
    public List<User> getCom(){
        return userService.list();
    }

    @GetMapping("/allClass")
    public List<Class> findAllClass() {

        return classService.list();
    }

    @GetMapping("/status/{status}")
    public List<Class> findStatus(@PathVariable("status") String status) {
        return classService.allClass(status);
    }

    @GetMapping("/orderByScore")
    public List<Class> getOrder() {
        return classService.getOrder();
    }

    @GetMapping("/findByIndex/{indexx}")
    public Class findByIndex(@PathVariable("indexx") Integer index) {

        return classService.getById(index);
    }

    @GetMapping("/deleteByIndex/{indexx}")
    public boolean deleteByIndex(@PathVariable("indexx") Integer index) {
        return classService.removeById(index);
    }


    @PostMapping("/add")
    public boolean add(@RequestBody Class c) {
        c.setNewTime(c.getNewTime().replace('/','.'));
//        System.out.println(c);
        classService.deleteByStu(c.getStuNum());
        return classService.save(c);
    }


    @PutMapping("/update")
    public boolean update(@RequestBody Class c) {
        return classService.updateById(c);
    }

    /*@GetMapping("/findByStatus")
    public List<Class> findClassByStatus(@RequestBody Class c) {

        return classService.allClass(c);
    }*/
}
